package mvc;

import java.util.ArrayList;

import org.geom.Vector3D;
import org.geom.curve.ICurve;
import org.geom.render.IRenderer;

public class CurveModel implements ICurve, IModel{

	public boolean dirty = true;
	public ICurve curve;
	
	public CurveModel(ICurve curve) {
		this.curve = curve;
	}

	//----------------------------------------------------
	//---------------------------------------------------- Model
	//----------------------------------------------------
	
	//-------------------------------------------------------- IModel implementation
	ArrayList<IRenderer> views = new ArrayList<IRenderer>();
	IModel parent = null;
	@Override
	public void addView(IRenderer v) {
		views.add(v);
	}
	@Override
	public void notifyAllViews() {
		for(IRenderer v : views) {
			v.render();
		}
		if(parent!=null)parent.notifyAllViews();
	}
	@Override 
	public IModel addParent(IModel parent) {
		this.parent = parent;
		return this;
	}
	
	@Override
	public Object getData() {
		return curve;
	}
	
	//----------------------------------------------------
	//---------------------------------------------------- Curve
	//----------------------------------------------------

	
	
	@Override
	public Vector3D binormal(float t) {
		return curve.binormal(t);
	}

	@Override
	public Vector3D derivateI(float t) {
		return curve.derivateI(t);
	}

	@Override
	public Vector3D derivateII(float t) {
		return curve.derivateII(t);
	}

	@Override
	public float getArc() {
		return curve.getArc();
	}

	@Override
	public ArrayList<Vector3D> getPoints() {
		
		if(dirty) {
			return curve.getPoints();
		}
		else return curve.getPointsWithoutResampling();
		
	}

	@Override
	public Vector3D normal(float t) {
		return curve.normal(t);
	}

	@Override
	public Vector3D sample(float t) {
		return curve.sample(t);
	}

	@Override
	public Vector3D tangent(float t) {
		return curve.tangent(t);
	}

	@Override
	public ArrayList<Vector3D> getPointsWithoutResampling() {
		return curve.getPointsWithoutResampling();
	}
}
